package photobox.order

import photobox.account.User

class Order {

    Integer  orderStatus  //0
    Integer  cancelStatus  //是否被取消
    Float   totalPrice //总价

    Integer  isInvoice //是否需要发票，1需要 ，0不需要
    Integer  invoiceType //发票类型 单位或个人
    Integer  invoiceSort //发票种类 交通或书
    String  invoiceTitle //发票title

    Date  dateCreated
    Date  lastUpdated

    static final int CANCEL_STATUS_NORMAL = 0
    static final int CANCEL_STATUS_USER  = 10  //客户取消
    static final int CANCEL_STATUS_SYSTEM = 20  //系统取消,比如发现订单异常
    static final int CANCEL_STATUS_RETURN = 30  //客户退货

    static final int ORDER_STATUS_NEW = 0    //新建订单
    static final int ORDER_STATUS_COMMIT = 10   //订单已提交,用户不能再修改,并等待付款
    static final int ORDER_STATUS_PAID = 20      //订单已付款,需要发货
    static final int ORDER_STATUS_MAKING = 30       //图片制作中
    static final int ORDER_STATUS_SEND = 40       //订单已发货等待确认收货
    static final int ORDER_STATUS_RECEIVED = 50   //订单已收货

    static final int IS_INVOICE_NO = 0
    static final int IS_INVOICE_YES = 1

    static final int INVOICE_TYPE_PERSONAL = 1       //个人
    static final int INVOICE_TYPE_ORGANIZATION = 2  //单位

    static final int INVOICE_SORT_TRAFFIC = 1       //交通
    static final int INVOICE_SORT_BOOK = 2          //书

    static belongsTo = [user: User]
    static hasMany = [items: OrderItem]

    static mapping = {
        table 'odr_order'
    }
    static constraints = {
        orderStatus  inList:[ORDER_STATUS_NEW, ORDER_STATUS_COMMIT, ORDER_STATUS_PAID,ORDER_STATUS_MAKING, ORDER_STATUS_SEND, ORDER_STATUS_RECEIVED]
        cancelStatus  inList: [CANCEL_STATUS_NORMAL, CANCEL_STATUS_USER, CANCEL_STATUS_SYSTEM, CANCEL_STATUS_RETURN]

        totalPrice  scale: 2, min: 0.0f, max: Float.MAX_VALUE
        isInvoice  inList: [IS_INVOICE_NO, IS_INVOICE_YES]
        invoiceType inList: [INVOICE_TYPE_PERSONAL, INVOICE_TYPE_ORGANIZATION]
        invoiceTitle  size: 0..200
        invoiceType inList: [INVOICE_SORT_TRAFFIC, INVOICE_SORT_BOOK]

    }
}
